module Language.ASTExpr.Parser where

import Language.ASTExpr.ParserAST
import Language.ASTExpr.ParserPretty
import Language.ASTExpr.Syntax

import Text.ParserCombinators.Parsec
import Text.ParserCombinators.Parsec.Token

-- some examples
test1 = "Add Const 1 Const 2"   -- 1 + 2
test2 = "Mul Add Const 1 Const 2 Add Const 3 EVar x"
test3 = "Let y := " ++ test1 ++ " " ++ test2
test4 = "Mul (Add Const 1 Const 2) (Add Const (-3) (Mul (EVar x) (EVar y)))"
test5 = "let [y := ( 1 + 2 ) * ( x ), z := 5] in y+z"

mainParser = try exprParser
             <|> expr

fromString :: String -> Either String Expr
fromString s = either (Left . show) (Right) $ parse mainParser "user_input" s
